package com.lff.mapper;


import com.lff.domain.Provider;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ProviderMapper {

    @Select("<script>" +
            "select * from smbms_provider" +
            "<where>" +
            "<if test=\"queryProCode!=null\">proCode like concat(\'%\',#{queryProCode},\'%\') </if>" +
            "<if test=\"queryProName!=null\">AND proName like concat(\'%\',#{queryProName},\'%\')</if>" +
            "</where>" +
            "</script>")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "proCode",column = "proCode"),
            @Result(property = "proName",column = "proName"),
            @Result(property = "proDesc",column = "proDesc"),
            @Result(property = "proPhone",column = "proPhone"),
            @Result(property = "proAddress",column = "proAddress"),
            @Result(property = "proFax",column = "proFax"),
            @Result(property = "createdBy.id",column = "createdBy")
    })
    List<Provider> findAll(@Param("queryProCode") String queryProCode, @Param("queryProName")String queryProName);

    @Select("select * from smbms_provider where id=#{id}")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "proCode",column = "proCode"),
            @Result(property = "proName",column = "proName"),
            @Result(property = "proDesc",column = "proDesc"),
            @Result(property = "proPhone",column = "proPhone"),
            @Result(property = "proAddress",column = "proAddress"),
            @Result(property = "proFax",column = "proFax"),
    })
    Provider findById(Long id);

    @Update("<script>" +
            "update smbms_provider" +
            "<set>" +
            "<if test=\"proCode!=null\">proCode=#{proCode},</if>" +
            "<if test=\"proName!=null\">proName=#{proName},</if>" +
            "<if test=\"proDesc!=null\">proDesc=#{proDesc},</if>" +
            "<if test=\"proContact!=null\">proContact=#{proContact},</if>" +
            "<if test=\"proPhone!=null\">proPhone=#{proPhone},</if>" +
            "<if test=\"proPhone!=null\">proAddress=#{proAddress},</if>" +
            "<if test=\"proPhone!=null\">proFax=#{proFax},</if>" +
            "<if test=\"proPhone!=null\">modifyBy=#{modifyBy.id},</if>" +
            "<if test=\"proPhone!=null\">modifyDate=#{modifyDate}</if>" +
            "</set>" +
            "where id=#{id}" +
            "</script>")
    void updateProvider(Provider provider);

   @Insert("Insert into smbms_provider(proCode,proName,proDesc,proContact,proPhone,proAddress,proFax,createdBy,creationDate)" +
           "values(#{proCode},#{proName},#{proDesc},#{proContact},#{proPhone},#{proAddress},#{proFax},#{createdBy.id},#{creationDate})")
    void addProv(Provider provider);

   @Delete("delete from smbms_provider where id=#{id}")
    Integer deleteById(Long id);
}
